package org.jiucai.app.admin;

import java.util.Map;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.jiucai.app.admin.auth.util.AdminUserUtil;
import org.jiucai.appframework.base.spring.service.IPageService;
import org.jiucai.cas.domain.UserInfo;

/**
 * Winner 页面基类
 * 
 * @author zhaidw
 * 
 */
public abstract class AdminBasePageService extends AdminBaseService implements
		IPageService {

	

	/**
	 * 返回拼接了基路径的视图页面路径，方便迁移
	 * 
	 * @return
	 */
	public String getViewPath(String viewName) {
		StringBuffer viewPath = new StringBuffer("");

		viewPath.append("admin/");
		viewPath.append(viewName);

		return viewPath.toString();
	}

	@Override
	public final String handleRequest(Map<String, Object> param,
			Map<String, Object> view) {
		
		try {
			// 页头，页脚动态数据处理实现

			UserInfo authUser = AdminUserUtil.getUser();
			view.put("adminSessAuthUser", authUser);

			// 子类实现
			return process(param, view);
			
		} catch (Exception e) {
			String errorMsg = ExceptionUtils.getFullStackTrace(e);
			log.error(errorMsg);
			view.put("errorMsg", errorMsg);
			return getViewPath("error/exception");
		}
	}

	

	/**
	 * 子类需要间接实现的页面请求处理类
	 * 
	 * @param param
	 * @param view
	 * @return
	 */
	public abstract String process(Map<String, Object> param,
			Map<String, Object> view);

}
